package co.fitstart.admin.web.controller.course;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.support.Result;
import com.demo2do.core.utils.JsonUtils;

import co.fitstart.admin.service.CourseRoundService;
import co.fitstart.admin.web.interceptor.MenuSetting;
import co.fitstart.entity.course.round.CourseRound;

/**
 * 课程课件
 * 
 * @author Ysy
 *
 */
@Controller
@RequestMapping("/special-rounds/{roundId}/special-coursewares/{rounds}")
@MenuSetting("menu-course")
public class SpeciallRoundCoursewareController {
	
	 @Autowired
	 private CourseRoundService courseRoundService;
	
	/**
	 * 
	 * @param roundId
	 * @param rounds
	 * @param status
	 * @return
	 */
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-special-course-arrange")
    public ModelAndView index(@PathVariable("roundId")Long roundId, @PathVariable("rounds")int rounds,
                              @RequestParam(name = "status", required = false, defaultValue = "prepare") String status){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/round-courseware/round-index");
        
        //1.load the round templates of first week 
        //2.load the diet of first week 
        CourseRound courseRound = courseRoundService.loadCourseRound(roundId);
        modelAndView.addObject("courseRound", courseRound);
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("rounds", rounds);
        modelAndView.addObject("status", status);
        
        return modelAndView;
    }
    
    /**
     * save 
     * 
     * @param roundId
     * @param rounds
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.PATCH)
    public @ResponseBody String save(@PathVariable("roundId")int roundId, @PathVariable("rounds")int rounds){
        
        Result result = new Result();
            
        try{
            
            result.success().message("保存成功！");
        }
        catch (Exception e) {
            
            result.fail().message("保存失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * Display link
     * 
     * @param roundId
     * @param rounds
     * @return
     */
    @RequestMapping(value = "/link", method = RequestMethod.GET)
    public ModelAndView link(@PathVariable("roundId")int roundId, @PathVariable("rounds")int rounds){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/round-courseware/round-link");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("rounds", rounds);
        
        return modelAndView;
    }
    
    
    /**
     * Display rest panel
     * 
     * @param roundId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/rest", method = RequestMethod.GET)
    public ModelAndView rest(@PathVariable("roundId")int roundId, 
                             @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/round-courseware/schedule-rest");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("rounds", rounds);
        modelAndView.addObject("schedules", schedules);
        
        return modelAndView;
    }
    
    /**
     * Set the day to be rest day
     * 
     * @param roundId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/rest", method = RequestMethod.PATCH)
    public @ResponseBody String onRest(@PathVariable("roundId")int roundId, 
                                         @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        Result result = new Result();
        
        try{
            
            result.success().message("设为休息日成功！");
        }
        catch (Exception e) {
            
            result.fail().message("设为休息日失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * Display create round movement panel
     * 
     * @param roundId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/movements/create", method = RequestMethod.GET)
    public ModelAndView create(@PathVariable("roundId")int roundId, 
                               @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/round-courseware/schedule-movement-create");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("rounds", rounds);
        modelAndView.addObject("schedules", schedules);
        
        return modelAndView;
    }
    
    /**
     * Create round movement
     * 
     * @param roundId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/movements", method = RequestMethod.POST)
    public @ResponseBody String onCreate(@PathVariable("roundId")int roundId, 
                                         @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        Result result = new Result();
        
        try{
            
            result.success().message("添加动作成功！");
        }
        catch (Exception e) {
            
            result.fail().message("添加动作失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * Display edit the round movement panel
     * 
     * @param roundId
     * @param movementId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/movements/{movementId}/edit", method = RequestMethod.GET)
    public ModelAndView edit(@PathVariable("roundId")int roundId, @PathVariable("movementId")int movementId,
                             @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/round-courseware/schedule-movement-edit");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("rounds", rounds);
        modelAndView.addObject("schedules", schedules);
        modelAndView.addObject("movementId", movementId);
        
        return modelAndView;
    }
    
    /**
     * edit the round movement
     * 
     * @param roundId
     * @param movementId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/movements/{movementId}", method = RequestMethod.PATCH)
    public @ResponseBody String onEdit(@PathVariable("roundId")int roundId, @PathVariable("movementId")int movementId, 
                                       @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        Result result = new Result();
        
        try{
            
            result.success().message("修改动作成功！");
        }
        catch (Exception e) {
            
            result.fail().message("修改动作失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    
    /**
     * Display delete the round movement panel
     * 
     * @param roundId
     * @param movementId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/movements/{movementId}/delete", method = RequestMethod.GET)
    public ModelAndView delete(@PathVariable("roundId")int roundId, @PathVariable("movementId")int movementId,
                               @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/round-courseware/schedule-movement-delete");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("rounds", rounds);
        modelAndView.addObject("schedules", schedules);
        modelAndView.addObject("movementId", movementId);
        
        return modelAndView;
    }
    
    

    /**
     * delete the round movement
     * 
     * @param roundId
     * @param movementId
     * @param rounds
     * @param schedules
     * @return
     */
    @RequestMapping(value = "/schedule-coursewares/{schedules}/movements/{movementId}", method = RequestMethod.DELETE)
    public @ResponseBody String onDelete(@PathVariable("roundId")int roundId, @PathVariable("movementId")int movementId, 
                                         @PathVariable("rounds")int rounds, @PathVariable("schedules")int schedules){
        
        Result result = new Result();
        
        try{
            
            result.success().message("删除动作成功！");
        }
        catch (Exception e) {
            
            result.fail().message("删除动作失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    
    

}
